/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import java.io.Serializable;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.ipti.br.tag.util.CalendarUtil;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author luancorumba
 */
@Entity
public class Activity extends AbstractEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Column(nullable = false)
    @Temporal(TemporalType.DATE)
    private Calendar efetivation;
    
    @ManyToOne
    private UnitySchedule unitySchedule;
    
    @ManyToOne
    private Unity unity;
    
    @ManyToOne
    private WorkTopic workTopic;
    
    @Override
    public void generateHash() {
        if (getId() == null) {
            String hash = ""
                    + ((this.getEfetivation() != null) ? CalendarUtil.getFormatedDate(this.getEfetivation()) : null)
                    + ((this.getUnitySchedule() != null) ? this.getUnitySchedule().getId() : null)
                    + ((this.getWorkTopic() != null) ? this.getWorkTopic().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public Activity() {
    }

    public Activity(Calendar efetivation, UnitySchedule unitySchedule) {
        this.efetivation = efetivation;
        this.unitySchedule = unitySchedule;
    }

    public Activity(Calendar efetivation, UnitySchedule unitySchedule, WorkTopic workTopic) {
        this.efetivation = efetivation;
        this.unitySchedule = unitySchedule;
        this.workTopic = workTopic;
    }

    public Calendar getEfetivation() {
        return efetivation;
    }

    public void setEfetivation(Calendar efetivation) {
        this.efetivation = efetivation;
    }

    public UnitySchedule getUnitySchedule() {
        return unitySchedule;
    }

    public void setUnitySchedule(UnitySchedule unitySchedule) {
        this.unitySchedule = unitySchedule;
    }

    public WorkTopic getWorkTopic() {
        return workTopic;
    }

    public void setWorkTopic(WorkTopic workTopic) {
        this.workTopic = workTopic;
    }

    public Unity getUnity() {
        return unity;
    }

    public void setUnity(Unity unity) {
        this.unity = unity;
    }

    @Override
    public String toString() {
        return "entity.Activity[ id=" + this.getId() + " ]";
    }
}
